home *** CD-ROM | disk | FTP | other *** search
/ Hráč 2004 August / Hrac_72_2004-08_dvd.iso / dema / Rapid Gun / rg_setup.exe / common / image_SobelFilter.fx < prev    next >
Text File  |  2004-04-19  |  2KB  |  66 lines

  1. // LF2 Engine
  2. // (C) 2002-3 7FX
  3. //---------------------------------------------------------------------------
  4. // Desc
  5. string desc : Description = "Image shader - Sobel edge detector.";
  6. // Shader type phase
  7. string type : Type = "image";
  8. //---------------------------------------------------------------------------
  9. // Constants
  10. const float4 cLum = {0.3f, 0.59f, 0.11f, 1.f};
  11. const float2 sampleOffsets[8] : SampleOffsets;
  12. // Render target texture
  13. texture RT : RenderTargetFSMap;
  14. //---------------------------------------------------------------------------
  15. sampler sRT = sampler_state
  16. {
  17.     Texture = <RT>;
  18.     MinFilter = POINT;
  19.     MagFilter = POINT;
  20.     AddressU = CLAMP;
  21.     AddressV = CLAMP;
  22. };
  23. //---------------------------------------------------------------------------
  24. // Pixel shader
  25. float4 PS(float2 uv: TEXCOORD0) : COLOR
  26. {
  27.     int i =0;
  28.     float4 c = .5;
  29.     float2 texCoords;
  30.     float4 texSamples[8];
  31.     float4 vertGradient;
  32.     float4 horzGradient;
  33.  
  34.     for(i =0; i < 8; i++)
  35.     {
  36.         texCoords = uv + sampleOffsets[i];    // add sample offsets
  37.         // take sample
  38.         texSamples[i] =  tex2D(sRT, texCoords); 
  39.         //  convert to b&w
  40.         texSamples[i] = dot(texSamples[i].rgb, 0.333333f/*cLum.rgb*/);
  41.     }
  42.     // VERTICAL Gradient
  43.     vertGradient = -(texSamples[0] + texSamples[5] + 2*texSamples[3]);
  44.     vertGradient += (texSamples[2] + texSamples[7] + 2*texSamples[4]);
  45.     
  46.     // Horizontal Gradient
  47.     horzGradient = -(texSamples[0] + texSamples[2] + 2*texSamples[1]);
  48.     horzGradient += (texSamples[5] + texSamples[7] + 2*texSamples[6]);
  49.  
  50.     // not optimized!
  51.     c = sqrt(horzGradient*horzGradient + vertGradient*vertGradient);
  52.  
  53.     return c;
  54. }
  55. //---------------------------------------------------------------------------
  56. technique vs0_ps20
  57. {
  58.     pass p0
  59.     {
  60.            ZEnable = false;
  61.         ZWriteEnable = false;
  62.    
  63.         PixelShader  = compile ps_2_0 PS();
  64.     }
  65. }
  66. //---------------------------------------------------------------------------